home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Magnum One
/
Magnum One (Mid-American Digital) (Disc Manufacturing).iso
/
d20
/
mxms_161.arc
/
MAXLIB.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-04
|
8KB
|
330 lines
/****************************************************************************/
/* */
/* Maxlib.c :Miscellaneous Maximus routines for MaxMail */
/* */
/****************************************************************************/
#include "MaxMail.h"
#include "bios.h"
int getch(void);
extern int CurColor;
/* Load in the MAXimus PARM file into our global structure */
int _pascal read_prm(char *pname)
{
int prmfile,x;
offsets=NULL;
if ((prmfile=sopen(pname,O_RDONLY | O_BINARY,SH_DENYNO,S_IREAD))==-1)
return(-1);
x=read(prmfile,(char *)&prm,sizeof(struct m_pointers));
if (prm.id != 'M' || prm.version != CTL_VER)
{
printf("\a\a");
aborterror(FILEOPEN,"Bad PARM file");
}
x=(int)(fsize(pname)-((int)tell(prmfile)));
offsets=(char *)malloc(x+10);
x=read(prmfile,offsets,x);
close(prmfile);
return TRUE;
}
/* Quick simple method to return size of file without
opening it */
long _pascal fsize(char *fname)
{
struct find_t find;
if(_dos_findfirst(fname,0xffff,&find))
return(0L); /* An error occured */
else return(find.size);
}
void _pascal get_currents()
{
unsigned x;
_dos_getdrive(&x);
sprintf(sdrive,"%c:",'A' + x - 1);
getcwd(temp,_MAX_DIR - 1);
strcpy(sdir,temp+2);
strcat(sdir,"\\");
}
/* Switch to drive,dir specified */
int _pascal switch_dir(char *dname)
{
unsigned x,y,z;
char tt[65];
strcpy(tt,dname);
x = strlen(tt) - 1;
y = strlen(tt) - 1;
if (tt[x] == '\\')
tt[x] = 0; /* Nullify trailing \ */
x = (toupper(dname[0])) - 'A' + 1;
_dos_setdrive(x,&z); /* Ignore 2nd parm */
if (tt[y] == ':') { /* Just a drive letter for temp directory ? */
_dos_getdrive(&z);
if (x != z) /* Change drive did not work */
return 1;
else { /* If it's just a drive, move to root */
chdir("\\");
return 0;
}
}
else return(chdir(tt));
}
/* Video stuff */
void _pascal chrout(char ch)
{
putchar(ch);
if (!IsLocal)
FossSendCh(ch);
}
void _pascal strout(char *outmsg)
{
printf(outmsg);
if (!IsLocal) {
check_carrier();
FossSendStr(outmsg);
check_carrier();
}
}
void _pascal cleareol(void)
{
int x;
x = CurColor;
setcolor(7);
if (LastUser.ansi)
strout("\x1b[K");
else if (LastUser.avatar) {
printf("\x1b[K"); /* Always send ansi to local console */
FossSendStr("\x07"); /* ^G */
}
setcolor(x);
}
void _pascal strin(char *inmsg)
{
unsigned ch;
int key,minutes;
char *p;
p = inmsg;
cflush();
if (!IsLocal) { /* Simulate GETS function for fossil */
minutes = timeon(); /* Establish a counter */
while (1) {
check_carrier();
while ((ch = FossGetCh()) == 0xFFFF) {
check_carrier();
if (timeon() > minutes + IDLETIME) /* User is idle too long */
aborterror(USERIDLE,NULL);
}
key = ch & 0xff;
if (key == '\r') { /* Carraige return */
break;
}
if (key == '\b') { /* Backspace */
if (p > inmsg) {
FossSendCh((byte)key);
putchar(key);
FossSendCh(' ');
putchar(' ');
FossSendCh((byte) key);
putchar(key);
p--;
}
}
else {
(*p) = (char) key;
p++;
FossSendCh((byte) key);
putchar(key);
}
*p = 0; /* Terminate */
}
*(p+1) = 0;
}
else gets(inmsg);
}
int _pascal chrin(void)
{
unsigned ch;
int minutes;
cflush();
if (IsLocal) {
ch = _bios_keybrd(_KEYBRD_READ);
if (ChatOk && ch == 0x2e00) { /* Chat mode is enabled */
chat();
ch = '!'; /* Return saying to restart menu */
}
return(ch & 0xff); /* Return saying to restart menu */
}
else {
minutes = timeon(); /* Establish a counter */
while ((ch = FossGetCh()) == 0xFFFF) {
check_carrier();
if (timeon() > minutes + IDLETIME) { /* User is idle too long */
aborterror(USERIDLE,NULL);
}
}
if (ChatOk && ch == 0x2e00) { /* Chat mode is enabled */
chat();
ch = '!'; /* Return saying to restart menu */
}
return(ch & 0x00ff);
}
}
int _pascal chrinwait(int tminutes)
{
unsigned ch;
int minutes;
cflush();
minutes = timeon(); /* Establish a counter */
if (IsLocal) {
while (_bios_keybrd(_KEYBRD_READY)) {
if (timeon() > minutes + tminutes) { /* User is idle too long */
return('\r');
}
}
ch = _bios_keybrd(_KEYBRD_READ);
if (ChatOk && ch == 0x2e00) { /* Chat mode is enabled */
chat();
ch = '!'; /* Return saying to restart menu */
}
return(ch & 0xff); /* Return saying to restart menu */
}
else {
while ((ch = FossGetCh()) == 0xFFFF) {
check_carrier();
if (timeon() > minutes + tminutes) { /* User is idle too long */
return('\r');
}
}
if (ChatOk && ch == 0x2e00) { /* Chat mode is enabled */
chat();
ch = '!'; /* Return saying to restart menu */
}
return(ch);
}
}
void _pascal cflush(void)
{
while (_bios_keybrd(_KEYBRD_READY)) /* Flush local console */
getch();
if (IsLocal)
return;
FossPurgeBuff(TRUE);
}
int _pascal check_carrier(void)
{
if (IsLocal)
return(FALSE);
if ((FossMdmStatus() & prm.carrier_mask) == 0) { /* Look at DCD(carrier bit) */
fclose(outfile);
aborterror(DROPCARRIER,NULL);
}
return(FALSE);
}
void _pascal logit(char *strng,char flag)
{
FILE *log;
char ttemp[40];
char *ttemp1;
char *month;
char *day;
if (LogMode == FALSE)
return;
ttemp1 = (char *) malloc(101);
if (ttemp1 == NULL) {
LogMode = FALSE;
aborterror(BADALLOC,NULL);
}
strcpy(ttemp, timestring());
strtok(ttemp," "); /* Strip Day of week */
month = strtok(NULL," ");
day = strtok(NULL," ");
tm = strtok(NULL," ");
if (Task)
sprintf(ttemp1,"%c %s %s %s MaxMail{%x} %s\n",flag,day,month,tm,Task,strng);
else sprintf(ttemp1,"%c %s %s %s MaxMail %s\n",flag,day,month,tm,strng);
if ((log = _fsopen(LogFile,"at+",SH_DENYRW)) == NULL) {
printf("\a\aError opening log file!\n");
LogMode = FALSE;
free(ttemp1);
return;
}
fputs(ttemp1,log);
free(ttemp1);
fclose(log);
}
char * _pascal timestring(void)
{
time_t aclock;
struct tm *newtime;
time(&aclock);
newtime = localtime(&aclock);
return(asctime(newtime));
}
void _pascal find_class(void)
{
int x;
for (x=0;x < MAXCLASS;x++)
{
if (LastUser.priv==prm.class[x].priv) {
UserClass=x;
break;
}
}
}
/* Clear the screen */
void _pascal clearscreen(void)
{
if (LastUser.ansi)
strout("\x1b[2J");
else if (LastUser.avatar) {
printf("\x1b[2,J"); /* Always send ansi to local console */
FossSendStr("\x0c"); /* ^L */
}
}